//file onchange
function onPreviewImg(fileObj, imgPreviewId) {
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		iePreview(fileObj, imgPreviewId);
	} else {
		noIEPreviewImg(fileObj, imgPreviewId);
	}
	var imgSource=$('#imgSource');
	if(imgSource)imgSource.val('upload');
}
//me
function onPreviewImg1(fileObj, imgPreviewId, imgPreviewId2) {
	if (navigator.userAgent.indexOf("MSIE") > 0) {
		iePreview(fileObj, imgPreviewId);
		iePreview(fileObj, imgPreviewId2);
	} else {
		noIEPreviewImg(fileObj, imgPreviewId);
		noIEPreviewImg(fileObj, imgPreviewId2);
	}
	var imgSource=$('#imgSource');
	if(imgSource)imgSource.val('upload');
}

//IE浏览器的图片预览
function iePreview(fileObj, imgPreviewId) {
	fileObj.select();
	fileObj.blur();
	var src = document.selection.createRange().text;
	document.selection.empty();
	if(typeof(imgPreviewId)=="string")
		$("#"+imgPreviewId).empty().attr("style", "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='" + src + "')");
		//document.getElementById(imgPreviewId).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale',src='" + src + "')";
	else
		$(imgPreviewId).empty().attr("style", "filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale', src='" + src + "')");
}

//火狐 谷歌浏览器的图片预览
function noIEPreviewImg(fileObj, imgPreviewId) {
//	var MAXWIDTH = 200;
//	var MAXHEIGHT = 200;
//var div = document.getElementById(imgPreviewId).parentNode;
	
	var imgPreview;
	if(typeof(imgPreviewId)=="string")
		imgPreview = document.getElementById(imgPreviewId);
	else
		imgPreview = imgPreviewId.previousSibling;
	
	if (fileObj.files && fileObj.files[0]) {
		//div.innerHTML = '<img id=' + imgPreviewId + '>';
		var img = imgPreview.firstChild.nextSibling;
//		img.onload = function() {
//			var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
//			img.width = rect.width;
//			img.height = rect.height;
//			img.style.marginLeft = rect.left + 'px';
//			img.style.marginTop = rect.top + 'px';
//		};
		var reader = new FileReader();
		reader.onload = function(evt) {
			img.src = evt.target.result;
		};
		reader.readAsDataURL(fileObj.files[0]);
	} else {
		fileObj.select();
		var src = document.selection.createRange().text;
		//div.innerHTML = '<img id=' + imgPreviewId + '>';
		var img = imgPreview.firstChild.nextSibling;
		img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
//		var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
//		status = ('rect:' + rect.top + ',' + rect.left + ',' + rect.width + ',' + rect.height);
//		var sFilter = 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
//		div.innerHTML = "<div id=divhead style='width:" + rect.width
//				+ "px;height:" + rect.height + "px;margin-top:" + rect.top
//				+ "px;margin-left:" + rect.left + "px;" + sFilter + src
//				+ "\"'></div>";
	}
}